﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using DHM.IRepository;
using DHM.IService;
using SqlSugar;

namespace DHM.Service {
    public class BaseService<T> : IBaseService<T> where T : class, new () {
        protected IBaseRepository<T> _baseRepository;
        /// <summary>
        /// 添加指定数据
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task<bool> AddAsync (T entity) {
            return await _baseRepository.AddAsync (entity);
        }
        /// <summary>
        /// 删除指定数据
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>

        public async Task<bool> DeleteAsync (T entity) {
            return await _baseRepository.DeleteAsync (entity);
        }
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>

        public async Task<bool> UpdateAsync (T entity) {
            return await _baseRepository.UpdateAsync (entity);
        }

        public async Task<T> FindAsync (int id) {
            return await _baseRepository.FindAsync (id);
        }

        public async Task<T> FindAsync (Expression<Func<T, bool>> func) {
            return await _baseRepository.FindAsync (func);
        }

        public async Task<List<T>> QueryAsync () {
            return await _baseRepository.QueryAsync ();
        }

        public async Task<List<T>> QueryAsync (Expression<Func<T, bool>> func) {
            return await _baseRepository.QueryAsync (func);
        }

        public async Task<List<T>> QueryAsync (int page, int size, RefAsync<int> total) {
            return await _baseRepository.QueryAsync (page, size, total);
        }
        /// <summary>
        /// 分页查询满足条件的数据
        /// </summary>
        /// <param name="func"></param>
        /// <param name="page"></param>
        /// <param name="size"></param>
        /// <param name="total"></param>
        /// <returns></returns>
        public async Task<List<T>> QueryAsync (Expression<Func<T, bool>> func, int page, int size, RefAsync<int> total) {
            return await _baseRepository.QueryAsync (func, page, size, total);
        }
        /// <summary>
        ///分页 获取满足条件的数据，并按照指定的排序类型展示
        /// </summary>
        /// <param name="func"></param>
        /// <param name="func2"></param>
        /// <param name="ordertype"></param>
        /// <param name="page"></param>
        /// <param name="size"></param>
        /// <param name="total"></param>
        /// <returns></returns>
        public async Task<List<T>> QueryAsyncOrder (Expression<Func<T, bool>> func, Expression<Func<T, object>> func2, OrderByType ordertype, int page, int size, RefAsync<int> total) {
            return await _baseRepository.QueryAsyncOrder (func, func2, ordertype, page, size, total);
        }
        /// <summary>
        /// 获取满足指定条件的数据的数量
        /// </summary>
        /// <param name="func"></param>
        /// <returns></returns>
        public Task<int> GetModuleCount (Expression<Func<T, bool>> func) {
            return _baseRepository.GetModuleCount (func);
        }
    }
}